package com.wen.Part4;


import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;

interface Condition{
    boolean condition(int i, int j);
}

@Slf4j
public class KMP {

    public static int[] getNext(String pattern){
        int[] next = new int[pattern.length()];
        next[0] = -1;
        int i = 1;
        int j = 0;
        while (i < pattern.length() - 1){
            if (j == -1 || pattern.charAt(i) == pattern.charAt(j)){
                ++i;
                ++j;
                if (pattern.charAt(i) == pattern.charAt(j)){
                    next[i] = next[j];
                }else{
                    next[i] = j;
                }
            }else{
                j = next[j];
            }
        }

        System.out.println(Arrays.toString(next));
        return null;
    }


    //  将一类数值放到另外一类数值后边
    public static void move(int[] list){
        if (list.length < 2) return;
        int i = 0;
        for (int j = 0; j < list.length; j++) {
            if (list[j] < 0) {
                int t = list[i];
                list[i] = list[j];
                list[j] = t;
                i++;
            }
        }
        System.out.println(Arrays.toString(list));
    }

    public static void main(String[] args) {

    }
}
